﻿using Electronic_work_order.Model;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Electronic_work_order.Interfacess.OA_Agency
{
    public class SQL_Agency : Interfacess_Agency
    {
        private readonly AppDbContext _context;

        public SQL_Agency(AppDbContext context)
        {
            _context = context;
        }

        public IEnumerable<object> Agency()
        {

            var Agencys = (from commission in _context.commissions
                          join Organizations in _context.organizations on commission.OrganizationId equals Organizations.OrganizationID
                          join application in _context.applications on commission.Aid equals application.Aid
                          join state in _context.Process_application_State on commission.Process_State_ID equals state.Process_State_ID
                          select new
                          {
                              commission.Agency_ID,commission.ApplicationName,Organizations.OrganizationName,
                              application.Aname,commission.Manager_id,commission.Director_Id,state.Process_State_Name,
                              commission.CreateTime
                          }).ToList();
            return Agencys;
        }

    }
}
